package com.project.controller;

import com.project.bean.OutCarBean;
import com.project.bean.OutOrderBean;
import com.project.bean.StorageBean;
import com.project.bean.UserBean;
import com.project.service.IOutCarService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;
import java.util.List;

@RequestMapping("outCar")
@RestController
public class OutCarController {
    @Autowired
    private IOutCarService carService;

    @RequestMapping("sumPrice")
    public Integer sumPrice(Integer userId) {
        return carService.sumPrice(userId);
    }

    ;

    @RequestMapping("findByUserId")
    public List<OutCarBean> findByUserId(Integer userId) {
        return carService.findByUserId(userId);
    }

    ;

    @RequestMapping("add")
    public String add(StorageBean storageBean, HttpServletRequest req){
        UserBean userBean =(UserBean)req.getSession().getAttribute("user") ;
        carService.add(storageBean,userBean.getId());

        return "ok";
    };

    @RequestMapping("update")
    public String  update(Integer carId,Integer newNum){
        carService.update(carId, newNum);
        return "ok";
    };

    @RequestMapping("del")
    public String del(Integer id){
        carService.del(id);
        return "ok";
    };

    @RequestMapping("outStorage")
    public String  outStorage(HttpServletRequest req, OutOrderBean outOrderBean){
        UserBean userBean =(UserBean)req.getSession().getAttribute("user") ;

        carService.outStorage(userBean.getId(), outOrderBean);
        return "ok" ;
    };

}
